//
//  LKStatusRetweetView.swift
//  LKWeibo
//
//  Created by like on 16/8/13.
//  Copyright © 2016年 like. All rights reserved.
//

import UIKit
import SnapKit

class LKStatusRetweetView: UIView {

    // 记录转发微博底部约束
    var retweetViewBottomConstraint: Constraint?
    
    var statusViewModel: LKStatusViewModel?{
        didSet{
            //
            contentLabel.text = statusViewModel?.statusModel?.retweeted_status?.text
            
            
            
            retweetViewBottomConstraint?.uninstall()
            //如果有  卸载约束，赋值，刷新约束
            if  statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count > 0{
                
                pictureView.pictureInfos = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                
                self.snp_makeConstraints { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                }
                //显示
                pictureView.hidden = false
            }else{
                
                self  .snp_makeConstraints { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                }
                //隐藏
                pictureView.hidden = true
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = RGB(237, green: 237, blue: 237)
        // 添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        // 添加约束
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(10)
        }
        
        pictureView.snp_makeConstraints { (make) in
            
            make.top.equalTo(contentLabel.snp_bottom)
            make.size.equalTo(CGSize(width: 100, height: 100))
            make.leading.equalTo((SCREENW - 250)/2)
            
        }
        
        self.snp_makeConstraints { (make) -> Void in
          retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
        
        
        
    }
    
    // MARK: - 懒加载控件
    // 转发微博
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15, maxWidth: SCREENW - 20)

    private lazy var pictureView: LKStatusPictureView = LKStatusPictureView()
    
    
}
